<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Cidades</title>
        <ui:include src="/WEB-INF/partials/layout/admin/includes.xhtml"/>
    </h:head>
    <h:body>
        <ui:include src="/WEB-INF/partials/layout/admin/menu.xhtml"/>

        <h:form prependId="false">
            <p:dialog modal="true" widgetVar="removeVar" id="remove" header="Confirmar Remoção?">
                <p:panel id="panelRemove">
                    <p:panelGrid columns="2"  style="width:100%" >
                        <h:outputLabel value="Cidade " for="cidade"  />
                        <h:outputText id="pais" value="#{CidadeCrudMB.entity.nome}"></h:outputText>
                        <h:outputLabel value="Estado" for="estado"/>
                        <ui:repeat value="#{CidadeCrudMB.entity.estado}" var="estado">
                            <h:outputText id="estado" value="#{estado.nome}" title="Estado" /> 
                        </ui:repeat>
                    </p:panelGrid>

                    <f:facet name="footer">
                        <p:commandButton value="Cancelar" oncomplete="removeVar.hide()" process="@this"/>
                        <p:commandButton value="Confirmar" oncomplete="removeVar.hide()"  update="lista" 
                                         action="#{CidadeCrudMB.delete()}" process="panelRemove">
                            <f:param value="#{CidadeCrudMB.entity.id}" />
                        </p:commandButton>
                    </f:facet>
                </p:panel>
            </p:dialog>


            <p:messages autoUpdate="true" />
            <h1><h:outputText value="Listagem de Cidades"/></h1>
            <p:dataTable value="#{CidadeCrudMB.cidades}" var="item" id="lista" rows="20">
                    <f:facet name="header">
                        <p:commandButton value="Cadastrar Cidade" action="#{CidadeCrudMB.newEntity}"
                                         oncomplete="window.location = './form.xhtml'" />
                    </f:facet>
                    <p:column>
                        <p:commandButton value="Editar" onclick="window.location='./form.xhtml?id=#{item.id}'" />
                        <p:commandButton value="Excluir" action="#{CidadeCrudMB.setEntity(item)}" 
                                         update="panelRemove" oncomplete="removeVar.show()"/>
                        <f:param name="id" value="#{item.id}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Id"/>
                        </f:facet>
                        <h:outputText value="#{item.id}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Nome"/>
                        </f:facet>
                        <h:outputText value="#{item.nome}"/>
                    </p:column>
                    <p:column style="width: 20%">
                        <f:facet name="header">
                            <h:outputText value="Estado"/>
                        </f:facet>
                        <ui:repeat value="#{item.estado}" var="estado" >
                            <h:outputText value="#{estado.nome}"/>
                        </ui:repeat>
                    </p:column>
                </p:dataTable>
        </h:form>
    </h:body>
</html>
